using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MyCustomModules_ViewAllDocs : System.Web.UI.UserControl
{
    string conn = System.Configuration.ConfigurationManager.AppSettings.Get("MSSQLConnectionString");
    Guid uguid;
    DataSet ds = new DataSet();
    DataSet dsStatus = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["UserGUID"] != null)
            uguid = new Guid(Request.QueryString["UserGUID"].ToString());
        else
            GetUserGUID();

        // Get status information
        dsStatus = mojoPortal.Data.SqlHelper.ExecuteDataset(
            conn, CommandType.Text, "select * from ut_Status");

        ds = mojoPortal.Data.SqlHelper.ExecuteDataset(
            conn, CommandType.StoredProcedure, "usp_GetMyDocumentListDetails",
            new System.Data.SqlClient.SqlParameter("@UserGUID", uguid));

        grdAllDocs.DataSource = ds.Tables[0];
        grdAllDocs.DataBind();
    }
    
    protected void GetUserGUID()
    {
        System.Data.SqlClient.SqlDataReader dr = mojoPortal.Data.SqlHelper.ExecuteReader
          (conn, CommandType.StoredProcedure, "usp_GetUserDetails",
          new System.Data.SqlClient.SqlParameter("@UserEmail", HttpContext.Current.User.Identity.Name.ToString()));
        if (dr.HasRows)
        {
            dr.Read();
            uguid = new Guid(dr["UserGuid"].ToString());
        }
        dr.Close();
    }

    protected string GetStatusImage(object value)
    {
        if (dsStatus.Tables.Count == 0)
            return "";
        int status = (int)value;
        return "~/" + dsStatus.Tables[0].Select("StatusID=" + status.ToString())[0]["ImagePath"].ToString();
    }

    protected string GetStatusLink(object value)
    {

        return "javascript:return OpenPopUp('" + System.Configuration.ConfigurationManager.AppSettings.Get("ShowRecieveDocLink") + "?DocID=" + 
            value.ToString() + "&userid=" + uguid.ToString() + "&fromMail=no');"; //ShowRecieveDocLink
    }

    protected string GetITRVLink(object value)
    {
        string str = (string)value;
        return str;
    }

    protected string GetITRVImage(object value)
    {
        if (dsStatus.Tables.Count == 0)
            return "";
        int status = (int)value;
        if (status > 5)
            return "~/Images/documentImage.png";
        else
            return "~/Images/blank.png";
    }
    protected string GetActualFileName(object value)
    {
        string str = (string)value;
        str = str.Remove(0, str.LastIndexOf("/") + 1);
        str = str.Remove(0, str.IndexOf("_") + 1);
        return str;
    }

    protected string GetPostMessageLink(object value)
    {

        return "javascript:return OpenPopUp('" + System.Configuration.ConfigurationManager.AppSettings.Get("ShowPostMessageLink") + "?DocID=" +
            value.ToString() + "&userid=" + uguid.ToString() + "&fromMail=no');"; //ShowRecieveDocLink
    }
}
